﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows;

namespace QLKS.ViewModels
{
    static public class ThuePhongViewModel
    {
        //Lấy Mã phiếu thuê
        static public int GetMaPhieuThue(string maphong)
        {
            int mp = -1;
            DataTable tb = GetChiTietPhieuThue(maphong,"");
            if (tb != null)
                mp = int.Parse(tb.Rows[0]["mapt"].ToString());
            return mp;
        }

        //Tạo phòng mới
        public static DataTable CreateNewThuePhong(string selectColumns)
        {
            DataTable tb = new DataTable();
            tb = Models.ThuePhongModel.CreateNewThuePhong(selectColumns);
            return tb;
        }

        //Lấy chi tiết phiếu thuê phòng
        public static DataTable GetChiTietPhieuThue(string maphong,string selectColumns)
        {
            DataTable tb = new DataTable();
            tb = Models.ThuePhongModel.GetChiTietPhieuThue(maphong, selectColumns);
            return tb;
        }
        //Lấy chi tiết phiếu thuê phòng
        public static DataTable GetChiTietPhongThue(string maphong, string selectColumns)
        {
            DataTable tb = new DataTable();
            tb = Models.ThuePhongModel.GetChiTietPhongThue(maphong, selectColumns);
            return tb;
        }
        //Lấy danh sách phiếu thuê phòng
        static public DataTable GetAllPhieuThuePhong(string columns)
        {
            DataTable tb = new DataTable();
            tb = Models.ThuePhongModel.GetAllPhieuThuePhong(columns);
            return tb;
        }


        //thêm nhân viên
        static public bool ThemPhieuThuePhong(int ma, string maphong, DateTime ngaythue, TimeSpan giothue, int loaithue, List<string> maKH)
        {
            try
            {
                int maphieuthue = Models.ThuePhongModel.ThemPhieuThuePhong(ma, maphong, ngaythue, giothue, loaithue);
                //int maphongnew = Models.ThuePhongModel.GetIdentity();
                Models.ThuePhongModel.ThemChiTietThuePhong(maphieuthue, maKH);
                Models.PhongModel.ThayDoiTrangThaiPhong(maphong, 2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "HotelManager", MessageBoxButton.OK, MessageBoxImage.Error);
                if (Models.DataProviderModel.IsOpen)
                    Models.DataProviderModel.Close();
                return false;
            }
            return true;
        }
    }
}
